package com.juxing.service.smsCenter.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.juxing.service.smsCenter.ISmsCenterService;
import com.juxing.service.smsCenter.SmsSendType;
import com.juxing.service.smsCenter.cache.ISmsCache;
import com.juxing.service.smsCenter.vendor.ISmsVendor;

/**
 * 
 * @author brochen
 * @mail mongibello@163.com
 * @created 2016年1月31日
 *
 */
public class SmsCenterServiceImpl implements ISmsCenterService {

	private static final Logger logger = LoggerFactory.getLogger(SmsCenterServiceImpl.class);
	
	@Autowired
	private ISmsVendor smsVendor;
	@Autowired
	private ISmsCache smsCache;

	@Override
	public int sendCode(String mobile, int type) {
		
		int cnt = smsCache.getHistoryCnt(mobile, 55);//前端60秒,缩5秒安全
		if(cnt > 1) {
			return -1;
		}
		cnt = smsCache.getHistoryCnt(mobile, 24 * 86400);//24小时发送次数
		if(cnt > 5) {//24小时发送超过5次
			return -2;
		}
		if(type == SmsSendType.REG) {
			smsVendor.sendRegChkCode(mobile);
		}
		return 0;
	}
	@Override
	public boolean checkCode(String mobile, int type, String code) {
		return smsVendor.validateChkCode(mobile, code);
	}
	
}
